package com.zk.springboot.modules.user;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import com.zk.springboot.interfaces.common.IWebFrame;
import com.zk.springboot.interfaces.common.IWebModule;
import com.zk.springboot.interfaces.common.IWebService;
import com.zk.springboot.interfaces.common.user.IUserService;

/**
 * 申明为模块服务
 * 
 * @author zk
 *
 */
@Service("userModule")
public class ServiceModule implements IWebModule {
	public static final String MODULE_NAME = "user";
	public static ServiceModule instance = new ServiceModule();
	List<IWebService> services = new ArrayList<IWebService>();
	ApplicationContext context;
	private IUserService userService;

	public void initModule(ApplicationContext context, IWebFrame frame) {
		instance.frame = frame;
		instance.context = context;
		instance.userService = context.getBean(IUserService.class);
		instance.services.add(instance.userService);
	}

	@Override
	public List<IWebService> getServiceList() {
		return instance.services;
	}

	@Override
	public <T> T getService(Class<T> requiredType) {
		return instance.context.getBean(requiredType);
	}

	private IWebFrame frame;

	public IWebFrame getFrame() {
		return instance.frame;
	}

	@Override
	public String appId() {
		return MODULE_NAME;
	}
}
